package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@ToString
public class OrderConfirmVo {
    /**
     * 收货地址列表
     */
    @Getter
    @Setter
    List<MemberAddressVo> address;
    /**
     * 购物车数据
     */
    @Getter @Setter
    List<OrderItemVo>  items;
    /**
     * 优惠卷信息
     */
    @Getter @Setter
    Integer integration;
    /**
     * 订单总额
     */
//    BigDecimal total;
    @Getter @Setter
    Map<Long,Boolean> stocks;

    /**
     * 订单的防重令牌
     * @return
     */
    @Getter @Setter
    String orderToken;
    public Integer getCount(){
        Integer num = 0;
        if (items!=null){
            for (OrderItemVo item : items) {
                num += item.getCount();
            }
        }
        return num;
    }
    public BigDecimal getTotal() {
        BigDecimal result = BigDecimal.ZERO;
        if (items!=null){
            for (OrderItemVo item : items) {
//                result.add(new BigDecimal(item.getPrice().toString()).multiply(new BigDecimal(item.getCount().toString())));
                BigDecimal total = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
               result = result.add(total);
            }
            return result;
        }else {
            return result;
        }
    }

    /**
     * 应付价格
     */
//    BigDecimal payPrice;
    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
